package com.common.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.common.R;

import java.lang.ref.WeakReference;


public class LoadingDialog extends Dialog {
    private static WeakReference<Context> mContext;
    
    private TextView mMessage;
    private ImageView mImage;
    private RelativeLayout mRootLayout;
    
    private static LoadingDialog mToast;
    
    public static void show(Context context, boolean canCancel, String text) {
        if (context == null) return;
        mContext = new WeakReference<Context>(context);
        if (mToast != null) {
            mToast.setCancelable(canCancel);
            mToast.setCanceledOnTouchOutside(canCancel);
            mToast.show();
        } else {
            mToast = new LoadingDialog(mContext.get());
            mToast.setCancelable(canCancel);
            mToast.setCanceledOnTouchOutside(canCancel);
            mToast.show();
        }
        mToast.mMessage.setText(text);
    }
    
    public LoadingDialog(Context context) {
        super(context, R.style.LoadingDialog);
        init();
    }
    
    public static void close() {
        if (mToast != null) {
            mToast.dismiss();
            mToast = null;
        }
    }
    
    private void init() {
        setContentView(R.layout.dialog_loading);
        mMessage = (TextView) findViewById(R.id.textView1);
    }
    
    
}
